
    <!-- Modal -->
    <div class="modal fade bs-example-modal-lg" id="subcolumn-asset-modal" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg" role="document" style="width:90%;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h3 class="modal-title">请选择媒资</h3>
                </div>
                <div class="modal-body">
                    <div class="ibox animated fadeInUp">
                        <div class="ibox-title">
                            <div class="ibox-tools rboor">
                                <a class="btn btn-primary btn-sm" id="batch-add-subcolumn-asset" href="javascript:void(0);">
                                    <i class="im-plus">
                                    </i>
                                    批量贴标签
                                </a>
                                <button class="btn btn-success btn-sm" href="javascript:void(0);" id="subcolumn-asset-table-refresh">
                                    <i class="im-spinner10 fa-spin">
                                    </i>
                                    刷新
                                </button>
                            </div>
                        </div>
                        <div class="ibox-content" style="background-color: #ffffff;color: inherit;padding: 15px 20px 20px 20px;border-color: #e7eaec;border-image: none;border-style: solid solid none;border-width: 1px 0px;">
                            <!-- search start -->
                            <div class="form-horizontal clearfix">

                                <div class="col-lg-3 col-sm-2 pl0">
                                    <div class="form-group">
                                        <label class="col-lg-4 col-sm-4 control-label">
                                            媒资模型：
                                        </label>
                                        <div class="col-lg-8 col-sm-7">
                                            <select class="input-sm form-control input-s-sm inline" id="content-model">
                                                <option value="App\Models\Entity\Asset\Video\Vasseti" selected>点播</option>
                                                <option value="App\Models\Entity\Asset\Vlive\Vchan">直播</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-3 col-sm-2 pl0">
                                    <div class="form-group">
                                        <label class="col-lg-4 col-sm-4 control-label">
                                            收费类型：
                                        </label>
                                        <div class="col-lg-8 col-sm-7">
                                            <select class="input-sm form-control input-s-sm inline" id="subcolumn-asset-charge-type">
                                                <option value="">
                                                    请选择
                                                </option>
                                                    <option value="0">免费</option>
                                                    <option value="1">收费</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-4 col-sm-4">
                                    <div class="form-group">
                                        <div class="col-lg-12 col-sm-12 input-group">
                                            <input class="input-sm form-control" placeholder="请输入关键字" type="text" id="subcolumn-asset-search-value">
                                                <span class="input-group-btn">
                                                    <button class="btn btn-sm btn-primary" type="button" id="subcolumn-asset-search">
                                                        搜索
                                                    </button>
                                                </span>
                                            </input>
                                        </div>
                                    </div>
                                </div>
                                <input type="hidden" name="_token" value="{{csrf_token()}}"/>
                            </div>
                            <!-- search end -->
                            <!-- 表格-媒资数据 -->
                            <table cellspacing="0" class="table table-striped table-bordered table-hover dataTables-example dataTable" id="subcolumn-asset-table" width="100%"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var tag_content_type = $('#content-model').val();
        var tag_id = 0;
        function addTagContent() {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('input[name="_token"]').val()
                    // 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });

            // 添加媒资按钮
            $('.add-subcolumn-asset').on('click', function() {
                $('#subcolumn-asset-modal').modal('show');
                tag_id = $(this).attr('tag_id');
            });
            /**
             * 媒资
             */
            // 媒资-datatables渲染
            subcolumnAssetTable = $('#subcolumn-asset-table').DataTable({
                // "processing": true,
                // 服务器端渲染
                "serverSide": true,
                "retrieve": true,
                // 请求数据的形式(get, post), 请求的路径
                ajax: {
                    url: "/admin/entity/column/subcolumns/content/query",
                    type: "POST",
                    data: function(d) {
                        //媒资模型
                        d.content_model = $('#content-model').val();
                        // 归类
                        d.vcat = $('#subcolumn-asset-vcat').val();
                        // 分类
                        d.vcattag = $('#subcolumn-asset-vcattag').val();
                        // 收费类型
                        d.charge_type = $('#subcolumn-asset-charge-type').val();
                        // 搜索框
                        d.search_value = $('#subcolumn-asset-search-value').val();
                        // 二级栏目id
                        d.subcolumn_id = $('#subcolumn_id').val();
                    },
                    // headers: {
                    //     'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    // }
                },
                columns: [{
                    orderable: false,
                    data: "id",
                    render: function(id) {
                        return '<input type="checkbox" data-id="' + id + '" name="checkbox-subcolumn-asset">'
                    },
                    title: '<input id="subcolumn-asset-check-all" name="" type="checkbox" value=""/>全选',
                    width: "5%"
                }, {
                    // 列名
                    title: "媒资ID",
                    // 数据
                    data: "id",
                    // 能否进行排序
                    orderable: true,
                    width: "10%"
                }, {
                    title: "名称",
                    data: "name",
                    orderable: true,
                    width: "10%"
                }, {
                    title: "标题",
                    data: "title",
                    orderable: true,
                    width: "10%"
                }, {
                    title: "简介",
                    data: "short_desc",
                    orderable: false,
                    width: "10%"
                },{
                    title: "标签",
                    data: "tags",
                    orderable: false,
                    width: "10%",
                    render: function(tags) {
                        if (typeof(tags)=="undefined" || tags.length < 1){
                            return '';
                        }else{
                            var dataarray = [];
                            $.each(tags, function(key, tag) {
                                dataarray.push(tag['name']);
                            });
                            return dataarray.join(',');
                        }
                    }
                },{
                    title: "语言",
                    data: "vlangs",
                    orderable: false,
                    width: "10%",
                    render: function(vlangs) {
                        var avlangs = [];
                        $.each(vlangs, function(key, vlang) {
                            avlangs.push(vlang['name']);
                        });
                        return avlangs.join(',');
                    }
                }, {
                    title: "操作",
                    orderable: false,
                    width: "5%",
                    "render": function(data, type, row, meta) {
                        return "<a class='btn btn-primary btn-xs' href='javascript:void(0);'" + "onclick='_addTagContent(\"" + row['id'] + "\")'>贴标签</a>";
                    }
                }],
                // 分页类型
                "pagingType": "full_numbers",
                "sLoadingRecords": "正在加载数据...",
                "sZeroRecords": "暂无数据",
                // 能否进行搜索
                "searching": false,
                "order": [
                    [1, "asc"]
                ],
                "dom": 'rt<"bottom"iflp<"clear">>',
                "language": {
                    "processing": "玩命加载中...",
                    "lengthMenu": "显示 _MENU_ 项结果",
                    "zeroRecords": "没有匹配结果",
                    "info": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                    "infoEmpty": "显示第 0 至 0 项结果，共 0 项",
                    "infoFiltered": "(由 _MAX_ 项结果过滤)",
                    "infoPostFix": "",
                    "url": "",
                    "paginate": {
                        "first": "首页",
                        "previous": "上一页",
                        "next": "下一页",
                        "last": "末页"
                    }
                },
                _fnPageChange: function() {}
            });
            // 使用col插件实现表格头宽度拖拽
            // $("#subcolumn-asset-table").colResizable();
            // 全选
            $('#subcolumn-asset-check-all').on('click', function() {
                $('#subcolumn-asset-table tr input[type="checkbox"][name="checkbox-subcolumn-asset"]').each(function() {
                    if ($(this).is(':checked')) {
                        $(this).prop("checked", false);
                    } else {
                        $(this).prop("checked", true);
                    }
                });
                // if($(this).is(':checked')) {
                //     console.log("选中");
                //     // alert("选中");
                // } else {
                //     console.log("取消选中");
                //     // alert("取消");
                // }
            });
            // 批量添加媒资
            $('#batch-add-subcolumn-asset').on('click', function() {

                var tag_content_id = [];
                $('#subcolumn-asset-table tr input[type="checkbox"][name="checkbox-subcolumn-asset"]').each(function() {
                    if ($(this).is(':checked')) {
                        tag_content_id.push($(this).attr("data-id"));
                    }
                });
                if (tag_content_id.length < 1) {
                    layer.msg("媒资不能为空, 请勾选媒资!", {
                        icon: 5
                    });
                    return false;
                }
                // 发送请求
                $.ajax({
                    url: '/admin/entity/tag_content/tag_contents',
                    type: 'POST',
                    cache: false,
                    dataType: 'json',
                    data: {
                        tag_id: tag_id,
                        tag_content_type: tag_content_type,
                        tag_content_id: tag_content_id
                    },
                    success: function(data) {
                        if (data.status) {
                            layer.alert(data.content, {
                                icon: 6
                            });
                            subcolumnAssetTable.draw();
                            if(typeof(subcolumnAssetSelectedTable)=='object'){
                                subcolumnAssetSelectedTable.draw();
                            }
                        } else {
                            layer.msg(data.content, {
                                icon: 5
                            });
                        }
                    },
                    error: function() {
                        layer.msg("异常！");
                    }
                });
            });
            // 搜索过滤
            $('#subcolumn-asset-search').on('click', function() {
                tag_content_type = $('#content-model').val();
                subcolumnAssetTable.draw();
            });
            // 刷新
            $('#subcolumn-asset-table-refresh').on('click', function() {
                // subcolumnAssetTable.draw();
                subcolumnAssetTable.ajax.reload(null, false);
            });
        }

        /**
         * [_addSubcolumnAsset 添加二级栏目-媒资关系]
         * @param {[type]} id [description]
         */
        function _addTagContent(id) {

            var tag_content_id = id;
            // alert(id);
            // 发送请求
            $.ajax({
                url: '/admin/entity/tag_content/tag_contents',
                type: 'POST',
                cache: false,
                dataType: 'json',
                data: {
                    tag_id: tag_id,
                    tag_content_type: tag_content_type,
                    tag_content_id: tag_content_id
                },
                success: function(data) {
                    if (data.status) {
                        layer.alert(data.content, {
                            icon: 6
                        });
                        subcolumnAssetTable.ajax.reload(null, false);
                        if(typeof(subcolumnAssetSelectedTable)=='object'){
                            subcolumnAssetSelectedTable.draw();
                        }
                    } else {
                        layer.msg(data.content, {
                            icon: 5
                        });
                    }
                },
                error: function() {
                    layer.msg("异常！");
                }
            });
        }
    </script>